package com.ipzoe.web.task;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ipzoe.act.domain.Activity;
import com.ipzoe.mem.domain.Member;
import com.ipzoe.mem.domain.MemberCard;
import com.ipzoe.mem.domain.MemberRechargePackage;
import com.ipzoe.mem.service.IMemberCardService;
import com.ipzoe.mem.service.IMemberRechargePackageService;
import com.ipzoe.mem.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class MemberTask {

    @Autowired
    private IMemberCardService iMemberCardService;
    @Autowired
    private IMemberService iMemberService;

    /**
     * 会员卡过期
     */
    @Transactional(rollbackFor = Exception.class)
    public void memberCardExpire(){
        //处理未过期，结束时间小于等于今天的，结束活动
        LambdaUpdateWrapper<MemberCard> luw = new LambdaUpdateWrapper<>();
        luw.set(MemberCard::getStatus, 2);
        luw.ne(MemberCard::getStatus, 2);
        luw.apply("date_format(expiry_day,'%y%m%d') <= date_format({0},'%y%m%d') ", DateUtil.today());
        iMemberCardService.update(luw);
    }

    /**
     * 会员过期
     */
    @Transactional(rollbackFor = Exception.class)
    public void memberExpire(){
        //处理未过期，结束时间小于等于今天的，结束活动
        LambdaUpdateWrapper<Member> luw = new LambdaUpdateWrapper<>();
        luw.set(Member::getMemberStatus, 2);
        luw.set(Member::getMemberLevel, 1);
        luw.ne(Member::getMemberStatus, 2);
        luw.eq(Member::getMemberLevel, 2);
        luw.apply("date_format(member_expire_time,'%y%m%d') <= date_format({0},'%y%m%d') ", DateUtil.today());
        iMemberService.update(luw);

    }

}
